package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.model.Course;

import java.util.ArrayList;

public class SearchResultActivity extends AppCompatActivity {
    private ListView listView;
    private ArrayList<Course> courseList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_result);
        listView = findViewById(R.id.listViewCourses);
        // TODO: 根据查询填充courseList
        courseList = new ArrayList<>();
        // 示例数据
        courseList.add(new Course("高等数学", "张"));
        courseList.add(new Course("大学英语", "李"));
        CourseAdapter adapter = new CourseAdapter(this, courseList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(SearchResultActivity.this, CourseDetailActivity.class);
                intent.putExtra("course", courseList.get(position));
                startActivity(intent);
            }
        });
    }
}
